/*
 * @(#)ProductMod.java 2011-12-09
 *
 * Copyright 2011 北龙中网（北京）科技有限责任公司. All rights reserved.
 */
package cn.shangjia.shop.controller.mod;

import javax.annotation.Resource;

import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.shangjia.common.dao.support.Page;
import cn.shangjia.common.domain.ProductOnline;
import cn.shangjia.common.util.StringUtils;
import cn.shangjia.shop.controller.base.AbstractController;
import cn.shangjia.shop.exception.NotFoundException;
import cn.shangjia.shop.service.ProductService;

/**
 * 产品相关 模块
 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
 * @version 1.0, 2011-12-09 14:05:38
 * @since 1.0
 */
@Controller
public class ProductMod extends AbstractController {
	
	@Resource
	private ProductService productOnlineService;
	
	/**
	 *  供应主页面
	 * 
	 * @param model
	 * @param userid
	 * @param dir
	 * @param pageno
	 * @return
	 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
	 */
	@RequestMapping("/shop/module/sale/index.html")
	public String mod_sale(ModelMap model , String userid, String dir , String pageno){
		if (StringUtils.isEmpty(userid))
			throw new NotFoundException("非法请求, 您所请求的页面不存在");
		Page<ProductOnline> page = productOnlineService.findProductPage(userid,dir, getInt(pageno), config.getProductCurrentPagesize());
		model.addAttribute("page", page);
		model.addAttribute("dir", dir);
		
		return "shop/module/sale/index";
	}
	
	
	/**
	 *  产品终端页
	 * 
	 * @param model
	 * @param userid
	 * @param id
	 * @return
	 * @author <a href="mailto:jinzhongze@knet.cn">jinzhongze</a>
	 */
	@RequestMapping("/shop/module/sale/detail.html")
	public String mod_sale_detail(ModelMap model, String userid, String id) {
		if (StringUtils.isEmpty(id))
			return mod_sale(model, userid, null, null);
		ProductOnline product = productOnlineService.getProductById(id);
		if (product == null) 
			return mod_sale(model, userid, null, null);
		model.addAttribute("productInfo", product);
		return "shop/module/sale/detail";
	}
	
}
